<?php
session_start();
	
	require_once '../lib/sql.utils.php';
	
	$sql_util = new SqlUtils();
	$result = $sql_util -> getRows('SELECT * FROM categoryDetails');
	$temp = '
		<div class="menu">
			Quản lý Tủ sách > Danh sách Các tủ sách
		</div>
		<hr />
		<div class="findbox">
			<select>
				<option>Tên tủ sách</option>
				<option>Tên danh mục</option>
				<option>Sách trong tủ sách</option>
				<option>Mô tả</option>
			</select>
			<input type="text" size="25" placeholder="Search..."/>
			<input type="button" value="Tìm kiếm"/>
		</div>
		<hr />
		<table border="0" class="detail">
			<tr class = "detail-head">
				<th>STT</th>
				<th>Tên tủ sách</th>		
				<th>Thuộc danh mục</th>
				<th>Sách trong tủ</th>
				<th>Ghi chú</th>
				<th>Sửa</th>
				<th><input type="checkbox" id="check"></th>
			</tr>';
			
	for ($i=0; $i < count($result); $i++) {
		$temp .= '<tr class="detail-main">';
			$temp .= '<td>'. ($i+1) .'</td>';
			$temp .= '<td>'.$result[$i]['categoryDetailName'].'</td>';
			$temp .= '<td>';
			$result_detail = $sql_util -> getRows('SELECT * FROM categories WHERE categoryId = '.$result[$i]['categoryId']);
			$temp .= $result_detail[0]['categoryName'];
			$temp .= '</td>';
			$temp .= '<td>';
			$result_book = $sql_util -> getRows('SELECT * FROM books WHERE categoryDetailId = '.$result[$i]['categoryDetailId']);
			for($k=0; $k< count($result_book) ; $k++){
				$temp .= $result_book[$k]['bookName'];
				if($k != count($result_book) - 1) $temp .= ',&nbsp';
			}
			
			$temp .= '</td>';
			$temp .= '<td>'.$result[$i]['categoryDetailDescription'].'</td>';
			$temp .= '<td>'.'<a onclick="displayFormEditCategoryDetail('.$result[$i]['categoryDetailId'].')">Sửa</a>'.'</td>';
			$temp .= '<td>'.'<input type="checkbox" name="check[]">'.'</td>';
		$temp .= '</tr>';
	}
	$temp .= '</table>';
	$temp .= 'Số lượng dòng hiển thị:';
	$temp .= '<select>
				<option>10</option>
				<option>20</option>
				<option>50</option>
			</select>';
	
	$_SESSION['data'] = 'displayAllCategoryDetail';
	echo $temp;
?>